﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace USMC.Net
{
    /// <summary>
    /// Interaction logic for GridSelectionWindow.xaml
    /// </summary>
    public partial class GridSelectionWindow : Window
    {
        MainWindow mainWIndow;
        public GridSelectionWindow(MainWindow window,int value)
        {
            InitializeComponent();
            mainWIndow = window;
            this.Top = window.Top + (window.Height - this.ActualHeight) / 3;
            this.Left = window.Left + (window.Width - this.ActualWidth) / 3;
            if (value != -1)
            {
                chb1.IsChecked = true;
                textBox.Text = value.ToString();
            }
        }
        int value;
        public int Value
        {
            get { return value; }
            set { this.value = value; }
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            int i = 0;
            if(chb1.IsChecked==false)
            {
                value=-1;
                this.DialogResult=true;
            }
            else if (Int32.TryParse(textBox.Text, out i))
            {
                if (mainWIndow.canvas.MaxSteps/(i) > 70*mainWIndow.canvas.Zoom)
                    MessageBox.Show("Слишком короткий интервал для текущего масштаба. Сетка может не отрисовываться.");
                value = i;
                this.DialogResult = true;
                    
            }
        }
    }
}
